package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.DayElecInfo;
import com.ruoyi.system.domain.vo.DayElecInfoVo;
import com.ruoyi.system.domain.vo.ElecCityCountVo;
import com.ruoyi.system.service.IDayElecInfoService;
import com.ruoyi.system.domain.dto.ElecInfoDto;
import com.ruoyi.system.domain.vo.WeekElecInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 每日用电情况Controller
 *
 * @author handsome
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/system/dayElecInfo")
@Api(tags = "用电管理模块")
public class DayElecInfoController extends BaseController {
    @Autowired
    private IDayElecInfoService dayElecInfoService;

    /**
     * 查询每日用电情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:dayElecInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(DayElecInfo dayElecInfo) {
        startPage();
        List<DayElecInfo> list = dayElecInfoService.selectDayElecInfoList(dayElecInfo);
        return getDataTable(list);
    }

    @ApiOperation("查询最近一周用电情况")
    @GetMapping("/lastWeekElec")
    public List<DayElecInfoVo> getLastWeekElecByUserId(@ApiParam(name = "userId", value = "用户ID", required = true) @RequestParam("userId") Long userId) {
        return dayElecInfoService.selectLastWeekElecByUserId(userId);
    }

    @ApiOperation("查询最近一月用电情况")
    @GetMapping("/lastMonthElec")
    public List<WeekElecInfoVo> getLastMonthElecByUserId(@ApiParam(name = "userId", value = "用户ID", required = true) @RequestParam Long userId) {
        return dayElecInfoService.selectLastMonthElecByUserId(userId);
    }

    @ApiOperation("查询昨日城市用电情况")
    @GetMapping("/yesterdaySum")
    public List<ElecCityCountVo> selectCityElecSumYesterday() {
        return dayElecInfoService.selectCityElecSumYesterday();
    }

    /**
     * 新增每日用电情况
     */
    @PreAuthorize("@ss.hasPermi('system:dayElecInfo:add')")
    @Log(title = "每日用电情况", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增用户每日用电情况")
    public AjaxResult add(@RequestBody ElecInfoDto dayElecInfo) {
        return toAjax(dayElecInfoService.insertDayElecInfo(dayElecInfo));
    }


    /**
     * 导出每日用电情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:dayElecInfo:export')")
    @Log(title = "每日用电情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DayElecInfo dayElecInfo) {
        List<DayElecInfo> list = dayElecInfoService.selectDayElecInfoList(dayElecInfo);
        ExcelUtil<DayElecInfo> util = new ExcelUtil<DayElecInfo>(DayElecInfo.class);
        util.exportExcel(response, list, "每日用电情况数据");
    }

    /**
     * 获取每日用电情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dayElecInfo:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(dayElecInfoService.selectDayElecInfoByUserId(userId));
    }


    /**
     * 修改每日用电情况
     */
    @PreAuthorize("@ss.hasPermi('system:dayElecInfo:edit')")
    @Log(title = "每日用电情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DayElecInfo dayElecInfo) {
        return toAjax(dayElecInfoService.updateDayElecInfo(dayElecInfo));
    }

    /**
     * 删除每日用电情况
     */
    @PreAuthorize("@ss.hasPermi('system:dayElecInfo:remove')")
    @Log(title = "每日用电情况", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(dayElecInfoService.deleteDayElecInfoByUserIds(userIds));
    }
}
